<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;
use think\Request;
class Atype extends Controller
{

    public function index()
    {
        $res = Db::name('atype')->select();
        // dump($res);
        // exit;
        $this->assign('res',$res);
        return $this->fetch();
    }
    
    public function add()
    {
        return $this->fetch();
    }

    public function add1()
    {
        $request = Request::instance();
        $data = $request->post();
        
       $hd = Db::table('atype')->insert($data);
       if($hd)
            {
                return $this->success('添加成功','atype/index');
            }
            else{
                return  $this->error('失败，请重新操作');
            }
    }

    public function update($a_type_id)
    {
        $res = Db::name('atype')->where('a_type_id',$a_type_id)->find();
        // dump($res);
        // exit;
        $this->assign('res',$res);
        return $this->fetch();
    }
    public function update1($a_type_id)
    {
        $request = Request::instance();
        $data = $request->post();
       
       $hd = Db::table('atype')->where('a_type_id',$a_type_id)->update($data);
       if($hd)
            {
                return $this->success('修改成功','atype/index');
            }
            else{
                return  $this->error('失败，请重新操作');
            }
    }
    public function delete($a_type_id)
    {
       $hd = Db::table('atype')->delete($a_type_id);
        if($hd)
             {
                 return $this->success('删除成功','atype/index');
             }
             else{
                 return  $this->error('失败，请重新操作');
             }
    }
}
